import os
import subprocess


def convert_doc_to_docx(doc_path, docx_path):
    subprocess.run(["unoconv", "-f", "docx", "-o", docx_path, doc_path])


def batch_convert_docs_to_docx(directory_path):
    for filename in os.listdir(directory_path):
        if filename.endswith(".doc"):
            doc_path = os.path.join(directory_path, filename)
            docx_path = os.path.join(directory_path, f"{os.path.splitext(filename)[0]}.docx")

            convert_doc_to_docx(doc_path, docx_path)

            print(f"Document converted: {doc_path} to {docx_path}")


# 替换为你的目录路径
directory_path = '/Users/edmond/Downloads/见习报告/22计科6班企业见习'

batch_convert_docs_to_docx(directory_path)
